package com.yuandian.management.service.impl;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yuandian.api.management.entity.ConfChannelMapping;
import com.yuandian.api.management.entity.ConfSystem;
import com.yuandian.management.mapper.ConfChannelMappingMapper;
import com.yuandian.management.service.ConfChannelMappingService;
import com.yuandian.management.service.ConfSystemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;
import java.util.stream.Collectors;

/**
 * -Service实现
 * @author zfsn
 * @date 2023-5-22
 */
@Service
public class ConfChannelMappingServiceImpl extends ServiceImpl<ConfChannelMappingMapper, ConfChannelMapping>
		implements ConfChannelMappingService {

	@Autowired
	private ConfChannelMappingMapper confChannelMappingMapper;

	@Autowired
	private ConfSystemService confSystemService;
	/**
	 * 分页查询
	 *
	 * @param confChannelMapping 筛选条件
	 * @return 通用返回对象
	 */
	@Override
	public Page<ConfChannelMapping> listPage(ConfChannelMapping confChannelMapping) {
		Page<ConfChannelMapping> confSystemPage = confChannelMappingMapper.listPage(new Page<>(confChannelMapping.getPageNum(), confChannelMapping.getPageSize()), confChannelMapping);
		Map<Integer, String> systemDomainMap = confSystemService.list().stream().collect(Collectors.toMap(ConfSystem::getId, ConfSystem::getName));
		for (ConfChannelMapping channelMapping : confSystemPage.getRecords()) {
			channelMapping.setSystemName(systemDomainMap.get(channelMapping.getSystemId()));
		}
		return confSystemPage;
	}
}